package com.tbit.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenmengran
 * @Description: 集合操作
 * @date 2019\12\10 001017:42
 */
public class CollectionUtils {

    public static <T> String listToString(List<T> list) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < list.size(); i++) {
            if (i == list.size() - 1) {
                sb.append(list.get(i));
            } else {
                sb.append(list.get(i) + ",");
            }
        }
        return sb.toString();
    }

    public static List<Integer> StringToList(String s) {
        if (s != null && !"".equals(s)) {
            String[] arr = s.split(",");
            List<Integer> list = new ArrayList<Integer>();
            for (int i = 0; i < arr.length; i++) {
                list.add(Integer.parseInt(arr[i]));
            }
            return list;
        }

        return null;
    }
}
